﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace WebApplication1
{
    public partial class issue : System.Web.UI.Page
    {
        SqlConnection cnn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");
        string id, cd, name, idate, exp, state;
        protected void Page_Load(object sender, EventArgs e)
        {
            id = Request.QueryString["id"];
            txtissno.Text = id;
            cnn.Open();
            SqlCommand cmd = new SqlCommand("select d.cdno,c.name from cdissue d,cdinfo c where c.cdno=d.cdno and issno='"+id+"'",cnn);
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                txtcdno.Text = Convert.ToString(dr.GetValue(0));
                txtcdname.Text = Convert.ToString(dr.GetValue(1));
            }
            DateTime dte=DateTime.Today;
            DateTime ans = dte.AddDays(10);
            txtissdate.Text = Convert.ToString(dte);
            txtexpire.Text = Convert.ToString(ans);
            txtstatus.Text = "Issued";
            cnn.Close();
        }

        protected void btniss_Click(object sender, EventArgs e)
        {
            cnn.Open();
            id = txtissno.Text;
            idate = txtissdate.Text;
            exp = txtexpire.Text;
            state = txtstatus.Text;
            SqlCommand cmd = new SqlCommand("update cdissue set issdate='" + idate + "',expire='" + exp + "',status='" + state + "' where issno='" + id + "'", cnn);
            cmd.ExecuteNonQuery();
            Response.Write("<script>alert('CD IS ISSUED')</script>");
            Response.Redirect("cdissue.aspx");
            cnn.Close();
        }
    }
}